<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/lx/admin/components/meta.html" />
    <title>注册统计 ${metaTitleSuffix!}</title>
    <#include "/lx/admin/components/stylesheets.html" />
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="6-3" />
            <#include "/lx/admin/components/menu.html" />
            <el-container>
                <#include "/lx/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row>
                            <el-col :span="12">
                                <div class="title theme-color1">注册统计</div>
                            </el-col>
                        </el-row>
                        <div class="search">
                            <div style="margin-bottom: 10px;">
                                <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" unlink-panels="true" :default-value="new Date">
                                </el-date-picker>
                                <el-select v-model="companyId" clearable filterable placeholder="公司">
                                    <el-option v-for="item in companies" :key="item.id" :label="item.name" :value="item.id">
                                    </el-option>
                                </el-select>
                                <el-select v-model="selectedProvince" clearable filterable placeholder="省份" @change="onProvinceChange">
                                    <el-option v-for="(item, index) in cityArray" :key="index" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                                <el-select v-model="selectedCity" clearable filterable placeholder="市县">
                                    <el-option v-for="(item, index) in childrenCityArray" :key="index" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                                <el-button @click="onSearch"><i class="el-icon-search"></i>筛选</el-button>
                                <el-button @click="goDownload"><i class="el-icon-download"></i>下载</el-button>
                            </div>
                            <div>
                                <el-radio-group v-model="countBy" @change="onSearch" style="margin-right: 100px;">
                                    <el-radio :label="0">按省市</el-radio>
                                    <el-radio :label="1">按公司</el-radio>
                                    <el-radio :label="2">按性别</el-radio>
                                </el-radio-group>
                                <el-radio-group v-model="order" @change="onSearch">
                                    <el-radio :label="0">降序</el-radio>
                                    <el-radio :label="1">升序</el-radio>
                                </el-radio-group>
                            </div>
                        </div>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%" v-if="countBy === 0">
                            <el-table-column prop="province" label="省市">
                            </el-table-column>
                            <el-table-column prop="count" label="人数">
                            </el-table-column>
                            <el-table-column prop="percentage" label="占比">
                                <template slot-scope="scope">
                                    {{ scope.row.percentage }}%
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%" v-if="countBy === 1">
                            <el-table-column prop="name" label="公司">
                            </el-table-column>
                            <el-table-column prop="count" label="人数">
                            </el-table-column>
                            <el-table-column prop="percentage" label="占比">
                                <template slot-scope="scope">
                                    {{ scope.row.percentage }}%
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%" v-if="countBy === 2">
                            <el-table-column prop="sex" label="性别">
                                <template slot-scope="scope">
                                    <span v-if="scope.row.sex == 0">男</span>
                                    <span v-if="scope.row.sex == 1">女</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="count" label="人数">
                            </el-table-column>
                            <el-table-column prop="percentage" label="占比">
                                <template slot-scope="scope">
                                    {{ scope.row.percentage }}%
                                </template>
                            </el-table-column>
                        </el-table>
                        <#include "/lx/admin/components/page.html" />
                        <!-- <div id="province-chart" style="width: 1000px; height:500px; margin-top: 10px;"></div>
                        <div id="company-chart" style="width: 1200px; height:500px; margin-top: 10px;"></div>
                        <div id="sex-chart" style="width: 800px; height:500px; margin-top: 10px;"></div> -->
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/lx/admin/components/footer.html" />
    </div>
    <#include "/lx/admin/components/scripts.html" />
    <script src="https://cdn.bootcss.com/echarts/4.1.0-release/echarts.min.js"></script>
    <script type="text/javascript" src="/lx/activity/assets/json/city.json"></script>
    <script>
        var vue = new Vue({
        el: '#app',
        data() {
            return {
                list: [],
                info: null,
                countBy: Number('${countBy!0}'),
                order: Number('${order!0}'),
                dateRange: '',
                companies: [],
                companyId: '',
                cityArray: city,
                childrenCityArray: [],
                selectedProvince: '',
                selectedCity: ''
            }
        },
        mounted: function() {
            this.list = ${items!'[]'}
            this.info = ${info!'""'}
            this.companies = ${companies!'[]'}
            var companyId = '${companyId!""}'
            if (companyId != '') {
                this.companyId = Number(companyId);
            }
            this.selectedProvince = '${province!}'
            this.selectedCity = '${city!}'
            if (this.selectedProvince) {
                for (var i = 0; i < this.cityArray.length; i ++) {
                    if (this.cityArray[i].value == this.selectedProvince) {
                        this.childrenCityArray = this.cityArray[i].children;
                    }
                }
            }
            var startTime = '${startTime!""}'
            if (startTime != '') {
                this.dateRange = new Array;
                this.dateRange.push('${startTime!}');
                this.dateRange.push('${endTime!}');
            }
            // this.initCharts();
        },
        methods: {
            initCharts() {
                var self = this;
                var provinceChart = echarts.init(document.getElementById('province-chart'));
                var provinceChartOption = {
                    title : {
                        text: '省份分布图',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        type: 'scroll',
                        orient: 'vertical',
                        right: 40,
                        top: 20,
                        bottom: 20,
                        data: self.info.provinceData.legendData
                    },
                    series : [
                        {
                            name: '省份',
                            type: 'pie',
                            radius : '55%',
                            center: ['40%', '50%'],
                            data: self.info.provinceData.seriesData,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                provinceChart.setOption(provinceChartOption);

                var companyChart = echarts.init(document.getElementById('company-chart'));
                var companyChartOption = {
                    title : {
                        text: '公司分布图',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        type: 'scroll',
                        orient: 'vertical',
                        right: 10,
                        top: 20,
                        bottom: 20,
                        data: self.info.companyData.legendData
                    },
                    series : [
                        {
                            name: '公司',
                            type: 'pie',
                            radius : '55%',
                            center: ['35%', '50%'],
                            data: self.info.companyData.seriesData,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                companyChart.setOption(companyChartOption);

                var sexChart = echarts.init(document.getElementById('sex-chart'));
                var sexChartOption = {
                    title : {
                        text: '性别分布图',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        type: 'scroll',
                        orient: 'vertical',
                        right: 40,
                        top: 20,
                        bottom: 20,
                        data: self.info.sexData.legendData
                    },
                    series : [
                        {
                            name: '省份',
                            type: 'pie',
                            radius : '55%',
                            center: ['55%', '50%'],
                            data: self.info.sexData.seriesData,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                sexChart.setOption(sexChartOption);
            },
            onProvinceChange(val) {
                // this.city = '';
                // var index = event.target.selectedIndex;
                // if (index == 0) {
                //     this.childrenCityArray = [];
                // } else {
                //     this.childrenCityArray = this.cityArray[index - 1].children; // index-1 第一项是“请选择”
                // }
                this.selectedCity = '';
                this.childrenCityArray = new Array;
                for (var i = 0; i < this.cityArray.length; i ++) {
                    if (this.cityArray[i].value == val) {
                        this.childrenCityArray = this.cityArray[i].children;
                    }
                }
            },
            onSearch() {
                var self = this;
                var keys = [
                    { key: 'companyId', value: self.companyId },
                    { key: 'province', value: self.selectedProvince },
                    { key: 'city', value: self.selectedCity },
                    { key: 'countBy', value: self.countBy },
                    { key: 'order', value: self.order }
                ]
                if (self.dateRange != null && self.dateRange.length > 1) {
                    keys.push({ key: 'startTime', value: self.dateRange[0] });
                    keys.push({ key: 'endTime', value: self.dateRange[1] });
                } else {
                    keys.push({ key: 'startTime', value: '' });
                    keys.push({ key: 'endTime', value: '' });
                }
                goPage(1, keys);
            }
        }
    })
    </script>
    <#include "/lx/admin/components/msg.html" />
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .operations {
        text-align: right;
    }

    .search {
        margin-top: 10px;
    }
    </style>
</body>

</html>